package com.zzf.concurrent.example.thread.pool;

import com.zzf.concurrent.example.thread.pool.exception.RejectException;
import com.zzf.concurrent.example.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.stream.IntStream;

/**
 * @author GaoFeng2017
 * @date 2019/8/9 10:57
 */
@Slf4j
public class ThreadPoolExample {
    public static void main(String[] args) {

        // ThreadPoolV1 poolV1 = new ThreadPoolV1(5, 10);
        ThreadPoolV1 poolV1 = new ThreadPoolV1(50, 4, 16, 32);
        poolV1.start();
        IntStream.rangeClosed(1, 60).forEach(i -> {

            try {
                poolV1.addTask(() -> {
                    // log.info("{} is get task {}", Thread.currentThread().getName(), i);
                    TimeUtil.sleep(1000);
                });
            } catch (RejectException e) {
                log.info("task {} is reject", i);
            }

        });

        TimeUtil.sleep(1200);

        poolV1.shutdown();
    }
}
